package com.xsmart.goods.services.wx;

import com.baomidou.mybatisplus.plugins.Page;
import com.xsmart.common.constant.ResultConstant;
import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.goods.dao.wx.WxGoodsShopDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WxGoodsShopService {
    @Autowired
    WxGoodsShopDao dao;

    @Autowired
    WxGoodsCategoryService wxGoodsCategoryService;

    /**
     * 查询店铺商品分类列表
     * @param requestBean
     * @return
     */
    public ResponseBean queryShopCategoryList(RequestBean requestBean){
        ResponseBean responseBean = requestBean.getResponseBean();
        Integer ruId = requestBean.getRequestParamInteger("ru_id");
        List<Map<String, Object>> shopInfo = dao.queryShopCategory(ruId);
        wxGoodsCategoryService.queryGoodsCategoryRoot(requestBean);
        responseBean.addResultItem("shopInfo", shopInfo);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

    /**
     * 查询店铺商品分类商品列表
     * @param requestBean
     * @return
     */
    public ResponseBean queryShopGoodsList(RequestBean requestBean){
        ResponseBean responseBean = requestBean.getResponseBean();
        Integer userId = requestBean.getRequestParamInteger("user_id");
        Integer catId = requestBean.getRequestParamInteger("cat_id");
        Integer id = requestBean.getRequestParamInteger("id");
        int currentPage = requestBean.getRequestParamInteger("currentPage", 1);
        int pageSize = requestBean.getRequestParamInteger("pageSize", 10);
        Map<String, Object> shopGoodsMap = new HashMap<>();
        shopGoodsMap.put("user_id", userId);
        shopGoodsMap.put("cat_id", catId);
        shopGoodsMap.put("id", id);
        Page<Map<String, Object>> page = new Page<>(currentPage, pageSize);
        page.setRecords(dao.queryShopGoodsList(page, shopGoodsMap));
        responseBean.addResultPageItem("shopGoodsList", page);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }
}
